<template>
  <view class="work-page">
    <!-- <view>{{ worksubData }}</view> -->
    <!-- 表格 根据不同模板的数据渲染部分，需要重写 -->
    <view class="temperature">
      <view class="text"> 当前温度°C </view>
      <view class="input">
        <input
          inputmode="decimal"
          @focus="currentFocus = -1"
          currentFocus="-1"
          :selection-start="0"
          :selection-end="10000"
          v-model="workMainData.real_temperature"
          placeholder="请输入当前温度"
        />
      </view>
      <view class="text"> 当前湿度% </view>
      <view class="input">
        <input
          inputmode="decimal"
          @focus="currentFocus = -1"
          :selection-start="0"
          :selection-end="10000"
          v-model="workMainData.real_humidity"
          placeholder="请输入当前湿度"
        />
      </view>
    </view>
    <uni-table border stripe emptyText="暂无更多数据">
      <!-- 表头行 -->
      <!-- <uni-tr class="active"> -->
      <uni-tr>
        <uni-th align="center" width="80px">组/位置</uni-th>
        <uni-th align="center" width="96px">采集数据</uni-th>
        <uni-th align="center" width="120px">要求</uni-th>
        <uni-th align="center" width="50px">目标值</uni-th>
        <uni-th align="center" width="50px">复核</uni-th>
        <!-- <uni-th align="center">采集时间</uni-th> -->
      </uni-tr>
      <!-- 表格数据行 -->
      <uni-tr v-for="(item, index) in worksubData" :key="item.id">
        <uni-td align="center">{{ item.grp }}/{{ item.position_id[1] }}</uni-td>
        <uni-td align="center" :class="{ active: item.no_pass }">
          <!-- <switch
            v-if="worktype[item.worktype_selection] === '判断'"
            :disabled="users.includes(currentUser[0])"
            :checked="item.check"
            @change="
              (e) => {
                item.check = e.detail.value
                item.datetime_work = dateShow()[0]
                item.datetimeUTC = dateShow()[1]
                item.operator_id = currentUser[0]
                item.no_pass = false
                updateMainNopass()
              }
            "
          /> -->
          <!-- {{ item.worktype_selection }} -->
          <checkbox-group
            v-if="worktype[item.worktype_selection] === '判断'"
            :disabled="users.includes(currentUser[0])"
            @change="
              (e) => {
                // console.log('check', Boolean(e.detail.value.length))
                item.check = Boolean(e.detail.value.length)
                item.datetime_work = dateShow()[0]
                item.datetimeUTC = dateShow()[1]
                item.operator_id = currentUser[0]
                item.no_pass = !Boolean(e.detail.value.length)
                // updateMainNopass()
              }
            "
          >
            <view :class="{ checked: item.check }">
              <label
                >合格:
                <checkbox value="checked" :checked="item.check" />
              </label>
            </view>
          </checkbox-group>

          <!-- :disabled="!workMainData.permit_user_ids.includes(currentUser[0])" -->
          <!-- 当事件处理函数不加()时，会在方法自动获取event,当加()里面即为传递的参数，如果还想获取event必须加上$,即$event作为参数的一部分传递 -->
          <input
            v-else-if="worktype[item.worktype_selection] === '数值'"
            :disabled="!worktoolStore.deviceId.currDeviceId || users.includes(currentUser[0])"
            :value="item.decimal ? item.real_value : item.real_value2"
            :inputmode="currInputMode"
            placeholder="请输入"
            :focus="currentFocus === item.id"
            :selection-start="0"
            :selection-end="10000"
            @confirm="onConfirm(index)"
            @focus="inputFocus(item)"
            @input="
              (e) => {
                let eValue = Number(e.detail.value)
                item.decimal ? (item.real_value = eValue) : (item.real_value2 = eValue)
              }
            "
            @blur="onBlur(item)"
          />
          <!-- @blur="onBlur(item)" -->
          <input
            v-else-if="worktype[item.worktype_selection] === '输入'"
            :disabled="users.includes(currentUser[0])"
            placeholder="输入文字"
            type="text"
            inputmode="text"
            :value="item.result || ''"
            @input="
              (e) => {
                item.result = e.detail.value
              }
            "
            @blur="
              (e) => {
                //设置当前操作时间及操作用户
                item.datetime_work = dateShow()[0]
                item.datetimeUTC = dateShow()[1]
                item.operator_id = currentUser[0]
                item.no_pass = false
                // updateMainNopass()
              }
            "
          />
          <view
            class="A4"
            v-else-if="worktype[item.worktype_selection] === '统计'"
            style="color: #1598fa"
            >{{ item.decimal ? item.real_value : item.real_value2 }}</view
          >
        </uni-td>
        <uni-td align="center">
          <view
            class="remark"
            v-if="
              worktype[item.worktype_selection] === '判断' ||
              worktype[item.worktype_selection] === '输入'
            "
            >{{ item.remark }}</view
          >
          <view
            class="min-max-value"
            v-else-if="
              worktype[item.worktype_selection] === '数值' ||
              worktype[item.worktype_selection] === '统计'
            "
            >{{
              item.decimal
                ? item.min_value.toFixed(3) + '~' + item.max_value.toFixed(3) + item.value_unit
                : item.min_value2.toFixed(2) + '~' + item.max_value2.toFixed(2) + item.value_unit
            }}</view
          >
        </uni-td>
        <uni-td align="center">
          <view v-if="worktype[item.worktype_selection] === '数值'">{{
            item.decimal ? item.target_value.toFixed(3) : item.target_value2.toFixed(2)
          }}</view>
        </uni-td>
        <uni-td align="center">
          <view
            class="photo"
            v-if="
              worktype[item.worktype_selection] === '判断' ||
              worktype[item.worktype_selection] === '输入'
            "
          >
            <wd-img
              :width="35"
              :height="35"
              :src="/* 'data:image/jpeg;base64,' +  */ item.photo"
              mode="aspectFit"
              enable-preview
              v-if="item.photo"
            >
              <template #loading>
                <view class="loading-wrap">
                  <wd-loading />
                </view>
              </template>
            </wd-img>
            <view class="button">
              <!-- <view class="button-photo" @click="onChooseImage(index)">拍照</view> -->
              <!-- <view v-if="item.photo" class="button-delete" @click="onDeleteImage(index)"
                >删除</view
              > -->
              <uni-icons
                class="button-photo"
                @click="onChooseImage(index)"
                type="camera-filled"
              ></uni-icons>
              <uni-icons
                v-if="item.photo"
                class="button-delete"
                @click="onDeleteImage(index)"
                type="clear"
              ></uni-icons>
            </view>
          </view>
          <!-- workMainData.permit_user_ids.includes(currentUser[0]) -->
          <view
            class="button-all"
            v-if="worktype[item.worktype_selection] === '统计'"
            @click="onOpenCollectData(index)"
          >
            统计</view
          >
          <view
            :class="{ 'button-all': workMainData.key }"
            style="text-align: center"
            v-if="worktype[item.worktype_selection] === '数值'"
            @click="onCheck(item, index)"
          >
            <!-- @focus="inputFocus(index)" -->
            <template v-if="!checkFlag[index]">
              <view v-if="workMainData.key">复测</view>
            </template>
            <template v-else>
              <view class="check">
                <input
                  :value="item.decimal ? item.check_value : item.check_value2"
                  :disabled="!worktoolStore.deviceId.currDeviceId"
                  inputmode="none"
                  placeholder="复测"
                  :focus="currentCheckFocus === item.id"
                  :selection-start="0"
                  :selection-end="10000"
                  @confirm="onConfirmCheck(index)"
                  @focus="onCheckFocus(item)"
                  @input="
                    (e) => {
                      let eValue = Number(e.detail.value)
                      item.decimal ? (item.check_value = eValue) : (item.check_value2 = eValue)
                    }
                  "
                  @blur="onBlurCheck(item)"
                />
              </view>
            </template>
          </view>
        </uni-td>
        <!-- <uni-td align="center" :class="{ active: item.no_pass }">{{ item.datetime_work }}</uni-td> -->
      </uni-tr>
    </uni-table>
    <!-- 采集数据弹出层 -->
    <uni-popup
      ref="collectDataPopup"
      type="bottom"
      border-radius="10px 10px 0 0"
      background-color="#ffffff"
    >
      <view class="collect-data-popup">
        <!-- 头部 -->
        <view class="collect-data-popup-title">
          <view class="collect-data-popup-title-left">采集数据</view>
          <view
            class="collect-data-popup-title-middle"
            @click="onSendData"
            v-if="worktoolStore.deviceId.currDeviceId !== '' && !worktoolStore.notBluedev"
          >
            <uni-icons type="arrow-up" class="nav-icons"></uni-icons>
          </view>
          <view class="collect-data-popup-title-right">
            <uni-icons
              type="closeempty"
              size="30"
              @click="onCloseCollectData"
              class="nav-icons"
            ></uni-icons>
          </view>
        </view>
        <!-- 内容 -->
        <view class="collect-data-popup-content">
          <view class="min-value margin-top-bottom">
            允许最小值：
            {{
              collectWorksubData?.decimal
                ? collectWorksubData?.min_value.toFixed(3)
                : collectWorksubData?.min_value2.toFixed(2)
            }}
          </view>
          <view class="max-value margin-top-bottom">
            允许最大值：
            {{
              collectWorksubData?.decimal
                ? collectWorksubData?.max_value.toFixed(3)
                : collectWorksubData?.max_value2.toFixed(2)
            }}
          </view>
          <view class="avg-value margin-top-bottom"> 平均值：{{ avg_value }} </view>
        </view>
        <!-- 收集数据表格 -->
        <uni-table border stripe emptyText="暂无更多数据">
          <!-- 表头行 -->
          <uni-tr>
            <uni-th align="center">采集值</uni-th>
          </uni-tr>
          <!-- 表格数据行 -->
          <uni-tr v-for="(item, index) in collectData" :key="item.id">
            <uni-td>
              <input
                v-model="item.value"
                @confirm="onAddData"
                :inputmode="currInputMode"
                :focus="collectCurFocus === index"
                @focus="collectInputFocus(index)"
                placeholder="请输入"
              />
            </uni-td>
            <uni-td>
              <view class="delete-data" @click="onDeleteData(index)">删除</view>
            </uni-td>
          </uni-tr>
          <!-- <uni-tr>
            <view class="add-data" @click="onAddData">添加明细行</view>
          </uni-tr> -->
        </uni-table>
        <!-- 底部 -->
        <button
          class="collect-data-popup-bottom"
          type="primary"
          size="mini"
          @click="onFinishCollectData"
        >
          完成
        </button>
        <!--为了button不被tabbar遮挡-->
        <view style="height: 50px"></view>
      </view>
    </uni-popup>
  </view>
</template>

<script setup>
const { safeAreaInsets } = uni.getSystemInfoSync()
import { onShow } from '@dcloudio/uni-app'
import { computed, ref, onMounted, onUnmounted } from 'vue'
//下面与template没有关系的脚本部分
import { useWorkmainStore, useWorksubStore, useWorktoolStore, useUserStore } from '@/stores'
import { dateShow } from '@/utils/utils.js'
import { emitter } from '@/EventBus'
const workMain = useWorkmainStore()
const worksubStore = useWorksubStore()
const worktoolStore = useWorktoolStore()
const userStore = useUserStore()
// const props = defineProps({
//   currentUser: Array,
// })
// // worksub数据
const worksubData = ref([])
// 当前work-main数据
const workMainData = ref({})
const workMainId = ref()
//当前使用的设备
// const deviceId = computed(() => {
//   return worktoolStore.deviceId
// })
//当前用户
const currentUser = ref([])
//可放行的用户
const users = ref([])
// 当前聚焦框
const currentFocus = ref(-1)
// 当前聚焦框
const currentCheckFocus = ref(-1)
//采集数据部分聚焦索引
const collectCurFocus = ref(-1)
//选中复测
const checkFlag = ref({})
function onCheck(item, index) {
  if (workMainData.value.key) {
    checkFlag.value[index] = !checkFlag.value[index]
    console.log('checkFlag', checkFlag.value)
    if (checkFlag.value[index]) {
      currentCheckFocus.value = item.id
    } else {
      currentFocus.value = item.id
    }
  }
}
//input组件inputmode，判断是否跳出软键盘
const currInputMode = computed(() => {
  //非自选量具，隐藏软键盘
  if (!worktoolStore.notBluedev) {
    console.log('none')
    return 'none'
    //自选量具，启动数字软软键盘
  } else {
    console.log('decimal')
    return 'decimal'
  }
})
//判断有设备列表否
function collectInputFocus(index) {
  collectCurFocus.value = index
}
function onBlur(item) {
  let real_val = Number(item.real_value)
  let real_val2 = Number(item.real_value2)
  item.decimal ? (item.real_value = real_val.toFixed(3)) : (item.real_value2 = real_val2.toFixed(2))
  item.datetime_work = dateShow()[0]
  item.datetimeUTC = dateShow()[1]
  item.operator_id = currentUser.value[0]
  item.deviceId = worktoolStore.deviceId.currDeviceId
  if (item.decimal) {
    if (item.real_value < item.min_value || item.real_value > item.max_value) {
      item.no_pass = true
    } else {
      item.no_pass = false
    }
  } else {
    if (item.real_value2 < item.min_value2 || item.real_value2 > item.max_value2) {
      item.no_pass = true
    } else {
      item.no_pass = false
    }
  }
  // updateMainNopass()
}
//聚焦在check_value
const focusCheckItem = ref(false)
function onConfirmCheck(index) {
  currentCheckFocus.value = worksubData.value[index + 1].id
  console.log('currentCheckFocus', currentCheckFocus.value)
}
function onCheckFocus(item) {
  //复测时设置为true,以便在蓝牙获取数据时，定位在check_value
  focusCheckItem.value = true
  console.log(focusCheckItem.value)

  currentCheckFocus.value = item.id
  // focusCheckData.value = item
  focusData.value = item
}
function onBlurCheck(item) {
  let check_val = Number(item.check_value)
  let check_val2 = Number(item.check_value2)
  item.decimal
    ? (item.check_value = check_val.toFixed(3))
    : (item.check_value2 = check_val2.toFixed(2))
  // item.datetime_work = dateShow()[0]
  // item.datetimeUTC = dateShow()[1]
  // item.operator_id = currentUser.value[0]
  // item.deviceId = deviceId.value.currDeviceId
  // if (item.decimal) {
  //   if (item.real_value < item.min_value || item.real_value > item.max_value) {
  //     item.no_pass = true
  //   } else {
  //     item.no_pass = false
  //   }
  // } else {
  //   if (item.real_value2 < item.min_value2 || item.real_value2 > item.max_value2) {
  //     item.no_pass = true
  //   } else {
  //     item.no_pass = false
  //   }
  // }
  // updateMainNopass()
}

let popuped = false
//当前数据
const focusData = ref({})
//当前复测数据
// const focusCheckData = ref({})

// 聚焦变化时事件
function inputFocus(item) {
  // console.log('focusIndex', index)
  //隐藏移动端键盘
  //当聚焦在real_value时，要将复测聚焦的标识设为false,以便蓝牙采集数据时定位
  //获取当前对象数组中item.id=itemid的数组索引号
  currentFocus.value = item.id
  console.log('item', item.id)
  focusData.value = item
  console.log('currentFocus', currentFocus.value)
  focusCheckItem.value = false
  // console.log(focusCheckItem.value)
  console.log('notBlue', worktoolStore.notBluedev)
  console.log('currInMode', currInputMode.value)

  //实际在@confirm已经将currentFocus++了，（confirm事件会自动将index++,并且马上进入@focus事件）
}
function onConfirm(index) {
  //获取当前对象数组中item.id=itemid的数组索引号
  // let i = worksubData.value.map((itm) => itm.id).indexOf(itemid)
  console.log('i', index)
  currentFocus.value = worksubData.value[index + 1].id
  console.log('itemid2', currentFocus.value)
}

// worktype对应关系
const worktype = ref({
  A1: '数值',
  // A2: '判断',
  B2: '判断',
  // A3: '输入',
  B3: '输入',
  A4: '统计',
})

const collectWorksubData = ref()
// 收集数据弹出层
const collectDataPopup = ref()
// 打开收集数据弹出层
function onOpenCollectData(index) {
  if (worktoolStore.deviceId.currDeviceId && !users.value.includes(currentUser.value[0])) {
    collectData.value = [
      {
        id: Date.now(),
        value: '',
      },
    ]
    //设置uni-popup开启状态，以便在蓝牙获取数据时用
    popuped = true
    collectDataPopup.value.open()
    collectWorksubData.value = worksubData.value[index]
  }
}
// 关闭收集数据弹出层
function onCloseCollectData() {
  collectWorksubData.value.datetime_work = dateShow()[0]
  collectWorksubData.value.datetimeUTC = dateShow()[1]
  collectWorksubData.value.operator_id = currentUser.value[0]
  collectWorksubData.value.deviceId = worktoolStore.deviceId.currDeviceId
  if (collectWorksubData.value.decimal) {
    if (
      collectWorksubData.value.real_value < collectWorksubData.value.min_value ||
      collectWorksubData.value.real_value > collectWorksubData.value.max_value
    ) {
      collectWorksubData.value.no_pass = true
    } else {
      collectWorksubData.value.no_pass = false
    }
  } else {
    if (
      collectWorksubData.value.real_value2 < collectWorksubData.value.min_value2 ||
      collectWorksubData.value.real_value2 > collectWorksubData.value.max_value2
    ) {
      collectWorksubData.value.no_pass = true
    } else {
      collectWorksubData.value.no_pass = false
    }
  }
  // console.log(collectWorksubData.value.no_pass)
  // updateMainNopass()
  //设置uni-popup关闭状态
  popuped = false
  collectDataPopup.value.close()
}

// 采集数据
const collectData = ref([
  {
    id: Date.now(),
    value: '',
  },
])
// 平均值
const avg_value = computed(() => {
  let i = 0
  let avg = 0
  let sum = 0
  collectData.value?.forEach((item) => {
    if (item.value !== 0 && item.value !== '') {
      i += 1
      sum += parseFloat(item.value || 0)
    }
  })
  avg = sum / i || 0
  return collectWorksubData.value?.decimal ? avg.toFixed(3) : avg.toFixed(2)
})
// 添加采集数据行
function onAddData() {
  setTimeout(() => {
    collectData.value?.push({
      id: Date.now(),
      value: '',
    })
    collectCurFocus.value++
    console.log('adddata')
  }, 250)
}
function onBlueAddData() {
  collectData.value?.push({
    id: Date.now(),
    value: '',
  })
  return collectData.value.length
}
// 删除采集数据行
function onDeleteData(index) {
  collectData.value?.splice(index, 1)
}
// 完成采集数据
function onFinishCollectData() {
  collectWorksubData.value.decimal
    ? (collectWorksubData.value.real_value = avg_value.value)
    : (collectWorksubData.value.real_value2 = avg_value.value)
  onCloseCollectData()
}

// 选择图片
import { pathToBase64 } from 'image-tools'
function onChooseImage(index) {
  if (!users.value.includes(currentUser.value[0])) {
    uni.chooseImage({
      count: 1,
      success: (res) => {
        const tempFilePaths = res.tempFilePaths[0]
        console.log(tempFilePaths)
        // image-tools插件实现 可用于uni-app、微信小程序、5+APP、浏览器（需允许跨域）
        pathToBase64(tempFilePaths)
          .then((base64) => {
            console.log(base64)
            worksubData.value[index].photo = base64
            // console.log(worksubData.value[index].photo)
            worksubData.value[index].datetime_work = dateShow()[0]
            worksubData.value[index].operator_id = currentUser.value[0]
            worksubData.value[index].no_pass = false
            // updateMainNopass()
          })
          .catch((error) => {
            console.error(error)
          })
        // 小程序实现方式
        /* const fs = uni.getFileSystemManager()
      fs.readFile({
        filePath: tempFilePaths,
        encoding: 'base64',
        success: (res) => {
          // const base64Data = `data:image/jpeg;base64,${res.data}`
          // console.log(base64Data)
          worksubData.value[index].photo = res.data
          console.log(worksubData.value[index].photo)
        },
        fail: (err) => {
          console.error('读取文件失败', err)
        },
      }) */
      },
    })
  }
}

function onDeleteImage(index) {
  uni.showModal({
    title: '提示',
    content: '确定删除该图片吗？',
    confirmText: '确定',
    cancelText: '取消',
    confirmColor: '#dd524d',
    success: (res) => {
      if (res.confirm) {
        worksubData.value[index].photo = ''
        worksubData.value[index].datetime_work = dateShow()[0]
        worksubData.value[index].operator_id = currentUser.value[0]
        worksubData.value[index].no_pass = false
        // updateMainNopass()
      }
    },
  })
}

//worksub.no_pass 更新workmain.no_pass,以便判断是否操作完，并且符合数据范围，可以上传
function updateMainNopass() {
  // console.log(workMainData.value)
  // console.log('updateMainNopass')
  workMainData.value.no_pass = !worksubData.value.every((element) => {
    return !element.no_pass
  })
  // console.log(workMainData.value.no_pass)
}
// onShow(async () => {
//   //获取当前登录用户
//   // currentUser.value = [userStore.userInfo.uid, userStore.userInfo.name]
//   //获取可放行用户
//   // users.value = userStore.userInfo.users
//   // console.log(users.value)
//   initProcess()
// })
onMounted(async () => {
  //接收WorkHead发出的事件
  // emitter.on('onClickBlue', onClickBlue)
  emitter.on('process', processBleData)
  emitter.on('onSendData', onSendData)
  currentUser.value = [userStore.userInfo.uid, userStore.userInfo.name]
  //获取可放行用户
  users.value = userStore.userInfo.users
  //获取worksubData
  // workMainId.value = worksubStore.currentWorkMainId
  // if (!worksubStore.records[workMainId.value]) {
  //   const res = await apiGetWorksub(workMainId.value)
  //   worksubStore.setRecords(workMainId.value, res.data.result.records)

  //   // await getWorksubData(worksubStore.currentWorkMainId)
  // }
  initProcess()
})
function initProcess() {
  workMainId.value = worksubStore.currentWorkMainId
  worksubData.value = worksubStore.records[workMainId.value]
  //获取workMainData
  const workMainIndex = workMain.records.findIndex((item) => item.id == workMainId.value)
  workMainData.value = workMain.records[workMainIndex]
  // deviceId.value = worktoolStore.deviceId
}
onUnmounted(() => {
  //关闭WorkHead所发出的事件
  // emitter.off('onClickBlue', onClickBlue)
  emitter.off('process')
  emitter.off('onSendData')
  updateMainNopass()
})
//蓝牙所采集的数据列表，第一项是采集的数据，第二项是单位
const gotValue = ref([])
// function onClickBlue(item) {
//   clickBlue(item, processBleData)
// }
function onSendData() {
  console.log('currInMode', currInputMode.value)
  let currFocus = 0
  if (!popuped) {
    currFocus = currentFocus.value
  } else {
    currFocus = collectCurFocus.value
  }
  // sendData(currFocus, currInputMode.value, currentCheckFocus.value)
  emitter.emit('sendData', [currFocus, currInputMode.value, currentCheckFocus.value])
}
//下面是采集数据后的处理，需要根据当前具体组件的内容重写
function processBleData(getValue) {
  console.log('process')
  let value = getValue[0]
  let unit = getValue[1]
  //当非计算平均采集数据时，获取蓝牙数据
  if (!popuped) {
    //当聚焦在复测数据框时
    console.log('focusCheckItem.value', focusCheckItem.value)
    if (focusCheckItem.value) {
      //获取当前复测数据行的索引，以便执行onConfirmCheck函数
      let checki = worksubData.value.findIndex((item) => item.id == focusData.value.id)
      console.log('checki', checki)
      if (focusData.value.decimal) {
        focusData.value.check_value = value.toFixed(3)
        console.log('check_value', focusData.value.check_value)
      } else {
        focusData.value.check_value2 = value.toFixed(2)
        console.log('check_value2', focusData.value.check_value2)
      }
      onConfirmCheck(checki)
      //当聚焦在正常采集数据时
    } else {
      console.log('fucusData', focusData.value.id)
      //获取当前数据的索引，以便执行onConfirm
      let i = worksubData.value.findIndex((item) => item.id == focusData.value.id)
      console.log('i', i)
      if (focusData.value.decimal) {
        focusData.value.real_value = value.toFixed(3)
        console.log('real_value', focusData.value.real_value)
      } else {
        focusData.value.real_value2 = value.toFixed(2)
        console.log('real_value2', focusData.value.real_value2)
      }
      focusData.value.datetime_work = dateShow()[0]
      focusData.value.datetimeUTC = dateShow()[1]
      focusData.value.operator_id = currentUser.value[0]
      focusData.value.deviceId = worktoolStore.deviceId.currDeviceId
      if (focusData.value.decimal) {
        if (
          focusData.value.real_value < focusData.value.min_value ||
          focusData.value.real_value > focusData.value.max_value
        ) {
          focusData.value.no_pass = true
        } else {
          focusData.value.no_pass = false
        }
      } else {
        if (
          focusData.value.real_value2 < focusData.value.min_value2 ||
          focusData.value.real_value2 > focusData.value.max_value2
        ) {
          focusData.value.no_pass = true
        } else {
          focusData.value.no_pass = false
        }
      }
      // updateMainNopass()
      onConfirm(i)
    }
  } else {
    //计算平均采集数据，蓝牙获取数据的操作
    let i = onBlueAddData()
    i = i - 2
    // console.log(i, value)
    collectData.value[i].value = value.toFixed(3)
    console.log(collectData.value[i])
    console.log(collectData.value[i].value)
    collectCurFocus.value++
  }
}
</script>

<style lang="scss" scoped>
.work-page {
  .margin-top-bottom {
    margin: 10px 0;
  }
  :deep(.nav-icons) {
    font-size: 24px !important;
    color: #1a73e8 !important;
    font-weight: 700 !important;
  }

  .check {
    background-color: #e0ffff;
  }

  .header {
    display: flex;
    flex-direction: column;
    align-items: center;
    border-bottom: 1px solid $border-color;

    &-prd_name {
      font-size: $text-font-size-m;
      color: $text-font-color-2;
    }
  }

  .active {
    color: #e64340;
  }

  .err-text {
    font-size: $text-font-size-s !important;
    color: $uni-color-error;
  }

  .photo {
    // width: 50px;
    // height: 70px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    margin: 0 auto;

    // .icon {
    //   padding: 6px;
    //   background: #f0f0f0;
    //   :deep(.uni-icons) {
    //     font-size: 18px !important;
    //   }
    // }
    .button {
      display: flex;
      flex-direction: row;
      justify-items: center;

      &-photo {
        padding: 6px;
        font-size: $text-font-size-s;
        color: $button-color;
      }

      &-delete {
        @extend .button-photo;
        color: $button-err;
      }
    }
  }

  .button-all {
    color: $button-color;
  }

  // .signature {
  //   margin: 10px;
  // }
  .collect-data-popup {
    margin: 10px;
    min-height: 40vh;

    &-title {
      padding: 10px;
      display: flex;
      justify-content: space-between;
      font-weight: 700;
      border-bottom: 1px solid $border-color;
    }

    .add-data {
      padding: 10px;
      font-size: $text-font-size-m;
      color: $button-color;
    }

    .delete-data {
      color: $button-color;
    }

    &-bottom {
      display: block;
      margin: 14px 0;
      padding: 2px 0;
    }
  }

  .document_image {
    width: fit-content;
    margin: 20px auto;
  }

  .checked {
    //border: 1px solid $brand-theme-color;
    background: rgba(194, 219, 239, 0.2);
  }
  // .temperature {
  //   display: flex;
  //   flex-direction: row;
  //   justify-content: center;
  //   width: 100%;
  //   .text {
  //     font-size: 12px;
  //     font-weight: 700;
  //     color: blueviolet;
  //     width: 70px;
  //   }
  //   .input {
  //     width: 30px;
  //   }
  // }
  //来自于AI
  .temperature {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center; // 添加垂直居中
    flex-wrap: wrap; // 允许换行
    width: 100%;
    gap: 10px; // 添加间距
    padding: 10px 0; // 添加上下内边距

    .text {
      font-size: 12px; // 增大字体
      font-weight: 700;
      color: blueviolet;
      white-space: nowrap; // 防止文字换行
    }

    .input {
      width: 50px; // 增加输入框宽度

      input {
        width: 100%;
        height: 36px;
        border: 1px solid #dcdfe6;
        border-radius: 4px;
        padding: 0 8px;
        box-sizing: border-box;
        background-color: #fff;

        &:focus {
          border-color: #1598fa;
          outline: none;
        }
      }
    }
  }
}
</style>
